package com.foodmarket.mapper;
import com.foodmarket.pojo.Buyers;
import com.foodmarket.pojo.Sellers;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    //根据买家名查询买家
    @Select("select * from buyers where username=#{username}")
    Buyers findByBuyerName(String username);

    //根据卖家名查询卖家
    @Select("select * from sellers where username=#{username}")
    Sellers findBySellerName(String username);

    //添加买家信息
    @Insert("insert into buyers(username,password,phone,email,name)"+
            "values(#{username},#{password},#{phone},#{email},#{name})")
    void addBuyer(@Param("username") String username, @Param("password") String password,@Param("phone") String phone,@Param("email") String email,@Param("name") String name);

    //添加卖家信息
    @Insert("insert into sellers(username,password,phone,email,name)"+
            "values(#{username},#{password},#{phone},#{email},#{name})")
    void addSeller(@Param("username")String username, @Param("password")String password,@Param("phone")String phone,@Param("email") String email,@Param("name") String name);

    //更新买家信息
    @Update("update buyers set name=#{buyers.name}, email=#{buyers.email},address=#{buyers.address}  where username=#{buyers.username}")
    void updateBuyer(@Param("buyers") Buyers buyers);


    //更新卖家信息
    @Update("update sellers set name=#{sellers.name}, email=#{sellers.email},store_name=#{sellers.storeName},address=#{sellers.address} where username=#{sellers.username}")
    void updateSeller(@Param("sellers") Sellers sellers);


    //更改买家密码
    @Update("update buyers set password=#{md5String} where username=#{username}")
    void updateBuyerPwd(@Param("md5String")String md5String,@Param("username")String username);

    //更改卖家密码
    @Update("update sellers set password=#{md5String} where username=#{username}")
    void updateSellerPwd(@Param("md5String")String md5String, @Param("username")String username);



}
